package com.yqd.lesson.actor.eight

import akka.actor.{Actor, ActorLogging, FSM, Props}


object StateMachine{
    sealed trait State
    case object Start extends State
    case object Mid extends State
    case object End extends State

    case class Data(i : Int)
}

class StateMachine extends Actor with ActorLogging with FSM[StateMachine.State, StateMachine.Data] {{
    import StateMachine._
    startWith(Start,Data(0))

    when(Start){
        case Event(_,Data(x)) =>{
            log.info("Start:" + x)
            goto(Mid)
        }
    }

    when(Mid){
        case Event(_,Data(x)) => {
            log.info("Mid:" + x)
            goto(End)
        }
    }

    when(End){
        case _ =>{
            log.info("End:")
            stay()
        }
    }

    initialize()
}

}
